#Code for Table S1

library(Matrix)
library(lme4)
library(lmerTest)
library(glmmTMB)
library(readxl)

data <- read_xlsx("C:/Users/username/Downloads/data_for_regression.xlsx", sheet = 8)
str(data)

m1 <- lm(`log # NSFC Grant` ~ `# Academy Member`, data = data)
summary(m1)

m2 <- lm(`log # R&D Expenditure` ~ `# Academy Member`, data = data)
summary(m2)

m3 <- lm(`log # Educational Expenditure` ~ `# Academy Member`, data = data)
summary(m3)

m4 <- lm(`% NSFC Grant` ~ `% Academy Member`, data = data)
summary(m4)

m5 <- lm(`% R&D Expenditure` ~ `% Academy Member`, data = data)
summary(m5)

m6 <- lm(`% Educational Expenditure` ~ `% Academy Member`, data = data)
summary(m6)



#Code for Table S2

library(Matrix)
library(lme4)
library(lmerTest)
library(glmmTMB)
library(readxl)

data <- read_xlsx("C:/Users/username/Downloads/data_for_regression.xlsx", sheet = 9)
str(data)

m1 <- lm(`A1` ~ `B`, data = data)
summary(m1)

m2 <- lm(`C1` ~ `D`, data = data)
summary(m2)

m3 <- lm(`E1` ~ `F`, data = data)
summary(m3)

m4 <- lm(G1` ~ `H`, data = data)
summary(m4)

m5 <- lm(`I1` ~ `J`, data = data)
summary(m5)

m6 <- lm(`K1` ~ `L`, data = data)
summary(m6)

m7 <- lm(`M1` ~ `N`, data = data)
summary(m7)

m8 <- lm(`O1` ~ `P`, data = data)
summary(m8)



#Code for Table S4

library(Matrix)
library(lme4)
library(lmerTest)
library(glmmTMB)
library(readxl)

data <- read_xlsx("C:/Users/username/Downloads/data_for_regression.xlsx", sheet = 6)
str(data)

m1 <- lmer(`Pub` ~ `Year` + (1|`Academician`), data = data)
summary(m1)
log_likelihood <- logLik(m1)
print(log_likelihood)

m2 <- lmer(`Citation` ~ `Year` + (1|`Academician`), data = data)
summary(m2)
log_likelihood <- logLik(m2)
print(log_likelihood)

m3 <- lmer(`Funding#` ~ `Year` + (1|`Academician`), data = data)
summary(m3)
log_likelihood <- logLik(m3)
print(log_likelihood)

m4 <- lmer(`Funding%` ~ `Year` + (1|`Academician`), data = data)
summary(m4)
log_likelihood <- logLik(m4)
print(log_likelihood)

data <- read_xlsx("C:/Users/username/Downloads/data_for_regression.xlsx", sheet = 7)
str(data)

m5 <- lmer(`Pub` ~ `Year` + (1|`Academician`), data = data)
summary(m5)
log_likelihood <- logLik(m5)
print(log_likelihood)

m6 <- lmer(`Citation` ~ `Year` + (1|`Academician`), data = data)
summary(m6)
log_likelihood <- logLik(m6)
print(log_likelihood)

m7 <- lmer(`Funding#` ~ `Year` + (1|`Academician`), data = data)
summary(m7)
log_likelihood <- logLik(m7)
print(log_likelihood)

m8 <- lmer(`Funding%` ~ `Year` + (1|`Academician`), data = data)
summary(m8)
log_likelihood <- logLik(m8)
print(log_likelihood)



#Code for Table S7 (Table 1)

if (!requireNamespace("MuMIn", quietly = TRUE)) {
  install.packages("MuMIn")
}
library(MuMIn)
library(Matrix)
library(lme4)
library(lmerTest)
library(glmmTMB)
library(readxl)

data <- read_xlsx("C:/Users/username/Downloads/data_for_regression.xlsx", sheet = 1)
str(data)

m1 <- lm(`H-Index` ~ `Foreign Education` + `West China`, data = data)
summary(m1)
log_likelihood <- logLik(m1)
print(log_likelihood)

m2 <- lm(`H-Index` ~ `Elected Age` + `Place of Birth` + `Specialised Field` + `Highest Education` + `Affiliation` + `Foreign Education` + `West China`, data = data)
summary(m2)
log_likelihood <- logLik(m2)
print(log_likelihood)

m3 <- lmer(`log` ~ `Foreign Education` + `West China` + (1|`Elected Age`) + (1|`Place of Birth`) + (1|`Specialised Field`) + (1|`Highest Education`) + (1|`Affiliation`), data = data)
summary(m3)
log_likelihood <- logLik(m3)
print(log_likelihood)
r_squared <- r.squaredGLMM(m3)
print(r_squared)

data <- read_xlsx("C:/Users/username/Downloads/data_for_regression.xlsx", sheet = 2)
str(data)

m4 <- lmer(`log` ~ `Foreign Education` + `West China` + (1|`Elected Age`) + (1|`Place of Birth`)  + (1|`Highest Education`) + (1|`Affiliation`), data = data)
summary(m4)
log_likelihood <- logLik(m4)
print(log_likelihood)
r_squared <- r.squaredGLMM(m4)
print(r_squared)

data <- read_xlsx("C:/Users/username/Downloads/data_for_regression.xlsx", sheet = 3)
str(data)

m5 <- lmer(`log` ~ `Foreign Education` + `West China` + (1|`Elected Age`) + (1|`Place of Birth`)  + (1|`Highest Education`) + (1|`Affiliation`), data = data)
summary(m5)
log_likelihood <- logLik(m5)
print(log_likelihood)
r_squared <- r.squaredGLMM(m5)
print(r_squared)

data <- read_xlsx("C:/Users/username/Downloads/data_for_regression.xlsx", sheet = 4)
str(data)

m6 <- lmer(`log` ~ `Foreign Education` + `West China` + (1|`Elected Age`) + (1|`Place of Birth`)  + (1|`Highest Education`) + (1|`Affiliation`), data = data)
summary(m6)
log_likelihood <- logLik(m6)
print(log_likelihood)
r_squared <- r.squaredGLMM(m6)
print(r_squared)


#Code for Figure S4

library(readxl)
library(ggplot2)
data <- read_xlsx("C:/Users/username/Downloads/data_for_regression.xlsx", sheet = 10)
str(data)

cor_test_result <- cor.test(data$Growth_Rank, data$Publication_Change, method = "pearson", use = "complete.obs")
print(cor_test_result)

model <- lm(Publication_Change ~ Growth_Rank, data = data)
summary(model)

ggplot(data, aes(x = Growth_Rank, y = Publication_Change)) +
  geom_point() +
  geom_smooth(method = "lm", color = "blue", fill = "grey") +  
  labs(x = "Growth_Rank",
       y = "Publication_Change") +
  theme_minimal()

install.packages("ggpubr")
library(ggplot2)

ggscatter(data, x = "Growth_Rank", y = "Publication_Change",
          add = "reg.line",                         
          conf.int = TRUE,                         
          cor.coef = TRUE,                          
          cor.method = "pearson",
          cor.coef.size = 5,
          xlab = "Growth Rank", 
          ylab = "Publication Change (%)",
          color = "steelblue") +
  ggtitle("Growth Rank vs Publication Change") +
  theme(plot.title = element_text(hjust = 0.5))